-- AnuStatue
-- Created by huanghr May/28/2016
-- 阿努比斯的雕塑

require "game/ui/form/dungeon/special/UIAnubisStatue"

-- 初始化
function initAnuStatue(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            local pos = self.gridData:getPos();

            -- 更新建筑访问
            AudioM.playFx("ui_open1");
            self:updateBuildingVisit();

                       -- 还有怪物未死亡
            if not DungeonM.isAllMonsterDead() then
                self:openBuildingView(nil, -20, getLocStr("cave_hide_item_dialog"), getLocStr("btn_text_leave"));
                return;
            end

            --  打开阿努比斯雕塑界面
            if UIMgr.getCurrentScene():isOpen("UIAnubisStatue") then
                UIMgr.getCurrentScene():removeFormByName("UIAnubisStatue");
            end
            local uiAnubis = UIAnubisStatue.create(pos);

            UIMgr.getCurrentScene():addForm(uiAnubis);

        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);

    -- 发光
    if self.gridData.need_shining == 1 then
        shiningEffect(self.icon, 70, 100);
    end
end

-- Anubis奖励
function onShowBuildingBonus(self, bonus, tips)

    if #table.keys(bonus) > 0 then

        if type(bonus[1]) == "number" then
            bonus = {bonus};
        end

        self:playBonusListEffect(bonus);
    end
end